﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title> 选择节点转向 </title>
    <script language="JavaScript" src="../Comm/JScript.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="Stylesheet" />
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script src="../../DataUser/JSLibData/CommonShowConfig.js"></script>
    <link rel="Stylesheet" href="../../DataUser/Style/ccbpm.css" />
    <script type="text/javascript">
        var WorkID;
        var FK_Flow;
        var FK_Node;
        var FID;
        var toNodeID = 0;//当前选中的节点
        var isFrameCross = GetQueryString("isFrameCross");
        if (isFrameCross == null || isFrameCross == undefined || isFrameCross == "" || isFrameCross == "null")
            isFrameCross = 0;
        //判断读秒关闭的参数是否存在
        if ("undefined" == typeof WF_WorkOpt_LeftSecond) {
            var WF_WorkOpt_LeftSecond = 30;
        }

        //初始化数据
        $(function () {
            WorkID = GetQueryString("WorkID");
            FK_Flow = GetQueryString("FK_Flow");
            FK_Node = GetQueryString("FK_Node");
            FID = GetQueryString("FID");

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            var data = handler.DoMethodReturnString("ToNodes_Init");
            if (data.indexOf("err@") != -1) {
                alert(data);
                return;
            }

            data = JSON.parse(data);
            var nodes = data.Nodes;
            var selectNodeID = data.SelectNode[0].NodeID;

            var html = "";
            var isSubYBD = false; //异表单

            for (var i = 0; i < nodes.length; i++) {
                var checked = "";
                //判断节点是否为异表单
                var node = nodes[i];
                if (node.NodeID == 0) {
                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";
                    html += "<span><input type='radio' id='RB_UnSameSheet' name='nodeSelect' value='RB_UnSameSheet' " + checked + " onclick='RBUnSameSheet(this);'>";
                    html += "<label for='RB_UnSameSheet'><b><font color=green>可以分发启动的异表单节点</font></b></label></span>";
                    html += "<br/><br>";
                    isSubYBD = true;
                    continue;
                }

                //已有人员直接显示到人员选择器a标签上
                var emps = new Entities("BP.WF.Template.SelectAccpers");
                emps.Retrieve("FK_Node", node.NodeID, "WorkID", WorkID);
                var addSpan = "";
                if (emps != null && emps.length > 0) {
                    for (var k = 0; k < emps.length; k++) {
                        if (k == 4) {
                            addSpan += emps[k].EmpName + "...";
                            break;
                        }
                        else {
                            if (k == emps.length - 1) {
                                addSpan += emps[k].EmpName;
                            }
                            else {
                                addSpan += emps[k].EmpName + ",";
                            }
                        }
                    }

                }
                addSpan = "<span style='color:black;' id='SP_" + node.NodeID + "'>(" + addSpan + ")</span>";

                //异表单选择可以同时发送给多个节点
                if (isSubYBD == true) {
                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";

                    html += "&nbsp;&nbsp;<input type='checkbox' id='CB_" + node.NodeID + "' name='nodeSelect' " + checked + ">";
                    html += "<label for='CB_" + node.NodeID + "'>" + node.Name + "</label>";

                    //上一步发送人选择或者是根据工程类项目由发送人选择
                    if (node.DeliveryWay == 4 || node.DeliveryWay == 21) {
                        html += "- <a id=\"acc_link_" + node.NodeID + "\"  href='javaScript:void(0)' onclick='SelectEmps(\"Accepter\",\"" + node.NodeID + "\")'>选择处理人" + addSpan + "</a>";
                    }
                    if (node.DeliveryWay == 43)
                        html += "- <a id=\"acc_link_" + node.NodeID + "\"  href='javaScript:void(0)' onclick='SelectEmps(\"AccepterOfOrg\",\"" + node.NodeID + "\")'>选择处理人" + addSpan + "</a>";

                    html += "<br/><br/>";

                }

                if (isSubYBD == false) {


                    if (node.NodeID == selectNodeID)
                        checked = "checked=checked";

                    html += "<input type='radio' id='RB_" + node.NodeID + "' name='nodeSelect' value='RB_" + node.NodeID + "' " + checked + "  onclick='SetUnEable(this);'>";
                    html += "<label for='RB_" + node.NodeID + "'>" + node.Name + "</label>";
                    //上一步发送人选择或者是根据工程类项目由发送人选择
                    if (node.DeliveryWay == 4 || node.DeliveryWay == 21) {
                        html += "- <a id=\"acc_link_" + node.NodeID + "\"   href='javaScript:void(0)' onclick='SelectEmps(\"Accepter\",\"" + node.NodeID + "\")'>选择处理人" + addSpan + "</a>";
                    }
                    if (node.DeliveryWay == 43)
                        html += "- <a id=\"acc_link_" + node.NodeID + "\"  href='javaScript:void(0)' onclick='SelectEmps(\"AccepterOfOrg\",\"" + node.NodeID + "\")'>选择处理人" + addSpan + "</a>";

                    html += "<br/><br/>";
                }

            }
            var tr = $(html);
            $("#TableNode").append(tr);
            $("input:radio:first").prop("checked", true);

            var int = setInterval("clock()", 1000);

        });

        function SetUnEable(ctrl) {
            SetEnable(true);
        }

        function RBUnSameSheet(ctrl) {
            if (ctrl.checked) {
                SetEnable(false);
            }
            else {
                SetEnable(true);
            }
        }

        function SetEnable(enable) {
            var arrObj = document.all;
            for (var i = 0; i < arrObj.length; i++) {
                if (typeof arrObj[i].type != "undefined" && arrObj[i].type == 'checkbox') {
                    arrObj[i].disabled = enable;
                }
            }
        }
        function SetRBSameSheetCheck() {
            var arrObj = document.all;
            for (var i = 0; i < arrObj.length; i++) {
                if (typeof arrObj[i].type != "undefined" && arrObj[i].id.valueOf('RB_SameSheet') != -1) {
                    arrObj[i].checked = true;
                    break;
                }
            }

        }

        function returnWorkWindowClose(data) {
            if (data != "取消")
                document.getElementById("SP_" + toNodeID).innerHTML = "(" + data + ")";

            $('#returnWorkModal').modal('hide');
        }


        //选择接受人

        function SelectEmps(OperHtml, nodeID) {
            toNodeID = nodeID;
            $('#modalHeader').text("选择接受人");
            modalIframeSrc = "./" + OperHtml + ".htm?FK_Node=" + FK_Node + "&FID=" + FID + "&WorkID=" + WorkID + "&FK_Flow=" + FK_Flow + "&ToNode=" + nodeID + "&IsSend=0" + "&s=" + Math.random();
            $('#iframeReturnWorkForm').attr('src', modalIframeSrc);
            $('#returnWorkModal').modal().show();
        }

        //选择节点发送
        function Send() {
            //获取选择的节点
            //获取同表单或者这个普通节点的选择的值
            var nodeID = $('input:radio:checked').val();
            var toNode = ""; // 跳转的节点
            if (nodeID == null || nodeID == "") {
                alert("您没有选择到达的节点");
                return;
            }
            //获取选择的异表单
            if (nodeID == "RB_UnSameSheet") {
                $.each($('input:checkbox'), function () {
                    if (this.checked)
                        toNode += this.id.replace("CB_", "") + ",";
                });
            } else
                toNode = nodeID.replace("RB_", "");
            if (toNode == "") {
                alert("您没有选择到达的节点");
                return;
            }

            //执行发送
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData();
            handler.AddPara("ToNodes", toNode);
            var data = handler.DoMethodReturnString("ToNodes_Send");
            if (data.indexOf('err@') == 0) { //发送时发生错误
                alert(data);
                return;
            }
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.WindowCloseReloadPage != null && typeof window.parent.WindowCloseReloadPage === "function") {
                    window.parent.WindowCloseReloadPage(data);
                } else {
                    if (typeof WindowCloseReloadPage != 'undefined' && WindowCloseReloadPage instanceof Function)
                        WindowCloseReloadPage(data);
                }
            } else {
                ChildrenPostMessage(data, "WindowCloseReloadPage");
            }

            if (data.indexOf('TurnUrl@') == 0) {  //发送成功时转到指定的URL
                var url = data;
                url = url.replace('TurnUrl@', '');
                SetHref(url);
                return;
            }


            if (data.indexOf('url@') == 0) {  //发送成功时转到指定的URL

                if (data.indexOf('Accepter') != 0 && data.indexOf('AccepterGener') == -1) {

                    //求出来 url里面的FK_Node=xxxx
                    var params = data.split("&");

                    for (var i = 0; i < params.length; i++) {
                        if (params[i].indexOf("ToNode") == -1)
                            continue;

                        toNodeID = params[i].split("=")[1];
                        break;
                    }
                    $('#modalHeader').text("选择接受人");
                    modalIframeSrc = "./Accepter.htm?FK_Node=" + FK_Node + "&FID=" + FID + "&WorkID=" + WorkID + "&FK_Flow=" + FK_Flow + "&ToNode=" + toNode + "&IsSend=0" + "&s=" + Math.random();
                    $('#iframeReturnWorkForm').attr('src', modalIframeSrc);
                    $('#returnWorkModal').modal().show();
                    return;
                }

                var url = data;
                url = url.replace('url@', '');
                SetHref(url);
                return;
            }
            data = data.replace('<br/>', '');
            data = data.replace('<br/>', '');
            data = data.replace('<br/>', '');
            data = data.replace('@', '<br/>@');
            data = data.replace(/@/g, '<br/>@');


            data = data.replace('@', '<br/>@');
            data = data.replace(/null/g, '');
            data = data.replace("<br><br/><br/>", '');

            data += " <div style='text-align:right;margin-right:10px;margin-bottom:10px'><button id='CloseBtn' type='button'  onclick='CloseAll();'><img src='../Img/Btn/Close.png' />关 闭(30秒)</button></div>";
            $(".Msg").show();
            $(".Msg").html(data);
            $("#TableNode").hide();
            $(".button-bar").hide();
        }

        function clock() {

            if ($("#CloseBtn").length == 0)
                return;
            WF_WorkOpt_LeftSecond >= 0 ? WF_WorkOpt_LeftSecond-- : clearInterval(int);
            $("#CloseBtn").html("<img src='../Img/Btn/Close.png' />关  闭(" + WF_WorkOpt_LeftSecond + "秒)");
            if (WF_WorkOpt_LeftSecond == 0)
                CloseAll();

            //if ($("#CloseBtn").length == 0)
            //    return;
            //num >= 0 ? num-- : clearInterval(int);
            //$("#CloseBtn").attr("value", "关    闭(" + num + "秒)");
            //if (num == 0)
            //    CloseAll();
        }

        //取消移交
        function CloseAll() {
            if (isFrameCross == 0) {
                // 取得父页面URL，用于判断是否是来自测试流程
                var pareUrl = window.top.document.referrer;
                if (pareUrl.indexOf("test") != -1 || pareUrl.indexOf("Test") != -1) {
                    // 测试流程时，发送成功刷新测试容器页面右侧
                    window.parent.parent.refreshRight();
                }

                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.close();
                    if (window.parent.parent != null && window.parent.parent != undefined
                        && pareUrl.indexOf("test") == -1 && pareUrl.indexOf("Test") == -1)
                        window.parent.parent.close();
                    window.parent.returnWorkWindowClose();
                }
            } else {
                window.parent.parent.close();
                ChildrenPostMessage('', "returnWorkWindowClose");
            }


            window.close();
        }


        //取消或者返回
        function Cancel() {
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.returnWorkWindowClose();
                } else {
                    $('body').append($('<div>' + "已取消操作" + '</div>'));
                    window.close();
                }
            } else {
                ChildrenPostMessage('', "returnWorkWindowClose");
            }
        }
    </script>
    <base target="_self" />
    <style>
        label {
            display: inline-block;
            max-width: 100%;
            margin-bottom: 0px;
            font-weight: normal;
        }

        input {
            width: 24px;
            height: 24px;
            margin-right: 6px !important;
            float: left;
        }

        .button-bar {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            background: #f2f2f2;
            border-top: solid 1px #e5e5e5;
            padding: 6px;
            text-align: center
        }

        input[type="radio"], input[type="checkbox"] {
            margin: 0;
        }
    </style>
</head>
<body>


    <div id="Div_ToNode" style="padding:15px; font-size:16px;">

        <div class="Msg" style="text-align: left;padding-left:55px; display:none;">
            <img src='../Img/loading.gif' alt="" />页面数据正在加载中，请稍候......
        </div>

        <div id="TableNode" style="width:100%;"></div>
        <br />
        <!--<input type=button id="Btn_Send" onclick="Send();" value="发送" />
        <input type=button id="Btn_Cancel" onclick="Cancel();" value="取消/返回" />-->

        <div class="button-bar">
            <button type=button onclick="Send();" id="Btn_Send" class="btn btn-primary">
                发送
            </button>

            <button type=button onclick="Cancel();" id="Btn_Cancel" class="btn btn-default">
                取消/返回
            </button>
        </div>
    </div>

    <!--杨玉慧加   提示信息弹出窗口-->
    <div class="modal fade" id="msgModal" data-backdrop="static">
        <div class="modal-dialog">
            <div class="modal-content" style="border-radius: 0px;">
                <div class="modal-header">
                    <button type="button" class="close" id="btnMsgModalOK1" aria-hidden="true" style="
                        opacity: 1; display: none;">
                        ×
                    </button>
                    <h4 class="modal-title">
                        提示信息
                    </h4>
                </div>
                <div class="modal-body" style="text-align: left; word-wrap: break-word;">
                    <div style="width:100%; border: 0px; height: 200px;" id="msgModalContent" name="iframePopModalForm">
                    </div>
                    <div style="text-align: right;">
                        <button type="button" id="btnMsgModalOK" class="btn" data-dismiss="modal">
                            <img src="../Img/Btn/Confirm.png" />确定
                        </button>
                    </div>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->

    <div class="modal fade" id="returnWorkModal" data-backdrop="static">
        <div class="modal-dialog" style="width:97%;height:90%">
            <div class="modal-content" style="height:90%">
                <div class="modal-header">
                    <button type="button" style="color:#333;border: solid 1px #ccc !important;width: 32px;height: 32px; border-radius:4px;margin-top:-6px; margin-right:-6px; float: right;background: #f5f5f5;border: none;" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="modalHeader">提示信息</h4>
                </div>
                <div class="modal-body" style="margin:0px;padding:0px;height:100%;">
                    <iframe style="width:100%;border:0px;height:100%;" id="iframeReturnWorkForm" name="iframeReturnWorkForm"></iframe>
                </div>
            </div><!-- /.modal-content -->'
        </div><!-- /.modal-dialog -->'
    </div>

</body>
</html>
